home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zdevcal.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  2.5 KB  |  74 lines

  1. /* Copyright (C) 1995, 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zdevcal.c,v 1.3 2000/09/22 04:18:17 lpd Exp $ */
  20. /* %Calendar% IODevice */
  21. #include "time_.h"
  22. #include "ghost.h"
  23. #include "gxiodev.h"
  24. #include "istack.h"
  25. #include "iparam.h"
  26.  
  27. /* ------ %Calendar% ------ */
  28.  
  29. private iodev_proc_get_params(calendar_get_params);
  30. const gx_io_device gs_iodev_calendar = {
  31.     "%Calendar%", "Special",
  32.     { iodev_no_init, iodev_no_open_device, iodev_no_open_file,
  33.       iodev_no_fopen, iodev_no_fclose,
  34.       iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  35.       iodev_no_enumerate_files, NULL, NULL,
  36.       calendar_get_params, iodev_no_put_params
  37.     }
  38. };
  39.  
  40. /* Get the date and time. */
  41. private int
  42. calendar_get_params(gx_io_device * iodev, gs_param_list * plist)
  43. {
  44.     int code;
  45.     time_t t;
  46.     struct tm *pltime;
  47.     struct tm ltime;
  48.     static const gs_param_item_t items[] = {
  49.     {"Year", gs_param_type_int, offset_of(struct tm, tm_year)},
  50.     {"Month", gs_param_type_int, offset_of(struct tm, tm_mon)},
  51.     {"Day", gs_param_type_int, offset_of(struct tm, tm_mday)},
  52.     {"Weekday", gs_param_type_int, offset_of(struct tm, tm_wday)},
  53.     {"Hour", gs_param_type_int, offset_of(struct tm, tm_hour)},
  54.     {"Minute", gs_param_type_int, offset_of(struct tm, tm_min)},
  55.     {"Second", gs_param_type_int, offset_of(struct tm, tm_sec)},
  56.     gs_param_item_end
  57.     };
  58.     bool running;
  59.  
  60.     if (time(&t) == (time_t)-1 || (pltime = localtime(&t)) == 0) {
  61.     ltime.tm_sec = ltime.tm_min = ltime.tm_hour =
  62.         ltime.tm_mday = ltime.tm_mon = ltime.tm_year = 0;
  63.     running = false;
  64.     } else {
  65.     ltime = *pltime;
  66.     ltime.tm_year += 1900;
  67.     ltime.tm_mon++;        /* 1-origin */
  68.     running = true;
  69.     }
  70.     if ((code = gs_param_write_items(plist, <ime, NULL, items)) < 0)
  71.     return code;
  72.     return param_write_bool(plist, "Running", &running);
  73. }
  74.